package com.thoughtworks;

import java.util.ArrayList;

/**
 * Created by bhagyas on 7/15/14.
 */
public class Library extends LibraryManager{





    public Library(Book[] books) {
        super();
    }
static ArrayList<Movies>checkedOutMovies=new ArrayList<Movies>();
    public static boolean returnedbook(String name,String librarynumber){
        boolean flag = false;
String exactlibrarynum= mapBookAndCustomer.get(name);
        for (int i = 0; i <=k ; i++) {
            if(name.equals(checkedoutbooks[i])&&exactlibrarynum.equals(librarynumber)){
                flag=true;
                checkedoutbooks[i]=null;
                mapBookAndCustomer.remove(name);
                k=k-1;
            }
        }

        return flag;
    }

    public static boolean checkout(Book books[],String name,String librarynumber) {

        for (int i = 0; i < books.length; i++) {
            if (name.equals(books[i].bookname)) {


                checkedoutbooks[++k] = name;
                mapBookAndCustomer.put(name,librarynumber);
                checkout = 1;
                return true;
            }

        }


        return false;

    }


    public static boolean checkOutMovie(ArrayList<Movies> movie, String moviename,String librarynumber){
        for(Movies movieset:movie){
            if(movieset.moviename.equals(moviename)){
                mapMovieAndCustomer.put(moviename,librarynumber);
                movie.remove(movieset);
                checkedOutMovies.add(movieset);
                return true;
            }
        }
        return false;
    }

    public static boolean returnMovie(ArrayList<Movies> movie, String moviename,String librarynumber){
        for(Movies movieset:checkedOutMovies){
            String expextedlibnum=mapMovieAndCustomer.get(moviename);
            if(movieset.moviename.equals(moviename)&&expextedlibnum.equals(librarynumber)){
                checkedOutMovies.remove(movieset);
                movie.add(movieset);
                mapMovieAndCustomer.remove(moviename);
                return true;
            }
        }
        return false;
    }


}
